﻿#ifndef PLOTMANAGE_H
#define PLOTMANAGE_H
#include <qcustomplot/qcustomplot.h>
#include <QMap>
#include "types.h"

#define CUSTOM_LINE_COLORS   14

#define PHASEA_CURR_IDX 0
#define PHASEB_CURR_IDX 1
#define PHASEC_CURR_IDX 2
#define PHASEA_VOL_IDX 3
#define PHASEB_VOL_IDX 4
#define PHASEC_VOL_IDX 5
#define INPUT_TORQUE_IDX 6
#define OUTPUT_TORQUE_IDX 7
#define INPUT_VELOCITY_IDX 8
#define ENCODER_VELOCITY_IDX 9
#define ENCODER_ANGLE_IDX 10
#define SENSORLESS_ANGLE_IDX 11
#define SENSORLESS_VELOCITY_IDX 12
#define D_AXIS_CURR_IDX 13
#define Q_AXIS_CURR_IDX 14
#define D_AXIS_VOL_IDX 15
#define Q_AXIS_VOL_IDX 16
#define D_TARGET_CURR_IDX 17
#define Q_TARGET_CURR_IDX 18
#define SVPWM_DUTYA_IDX 19
#define SVPWM_DUTYB_IDX 20
#define SVPWM_DUTYC_IDX 21
#define DC_CURRENT_IDX 22
#define AGNLE_DIFF_IDX 23

class PlotManage
{
public:
    PlotManage(QCustomPlot *plot);
    int AddGraph(QString name, QColor color, int dataIdx);
    int AddGraph(int dataIdx);
    void removeGraph(int dataIdx);
    void DisplayData(u32 id_mask, QList<float>data, int value);
    void replot();
    QList<int> &getIds();
    int plot_points;
    bool b_start;
private:
    bool b_reflash;
    QCustomPlot *plot;
    /* Line colors */
    QColor line_colors[CUSTOM_LINE_COLORS];
    QMap<int, QCPGraph*> graphs;
    QMap<QString, int> idMaps;
    QList<int> ids;
    int channels;
};

#endif // PLOTMANAGE_H
